package com.ny.Demo519;

import java.util.*;

public class TestMap {
    public void addEmp(Map<String, Emp> map, Emp emp) {
        map.put(emp.getNumber(), emp);
    }

    public void findAllEmp(Map<String, Emp> map) {
        for (Emp emp : map.values()) {
            System.out.println(emp);
        }
    }

    public Emp findEmpName(Map<String, Emp> map, String empName) {
        for (Emp emp : map.values()) {
            if (empName.equals(emp.getName())) {
                return emp;
            }
        }
        return null;
    }

    public void deleteEmp(Map<String, Emp> map, String empNumber) {
        map.remove(empNumber);
    }

    public Emp findEmpByNumber(Map<String, Emp> map, String empNumber) {
        return map.get(empNumber);
    }

    public void updateAgeByNumber(Map<String, Emp> map, String empNumber, int newAge) {
        Emp emp = map.get(empNumber);
        if (emp != null) {
            emp.setAge(newAge);
        }
    }
}